Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added validation and customization function in ghost app #3403

Merged
merged 3 commits into from
Jul 24, 2022

Conversation

droot
Copy link
Contributor

@droot droot commented Jul 21, 2022

This PR does the following:

  • Adds a package specific validation function for blog host
  • Adds a customization function for blog host
  • Misc updates due to running kpt fn render

@droot
Copy link
Contributor Author

droot commented Jul 21, 2022

@bgrant0607 @yuwenma @justinsb Added some package specific validation and customization function. Since they are package specific, I wrote them in starlark.

Please take a look and let me know what you think.

@yuwenma
Copy link
Contributor

yuwenma commented Jul 21, 2022

Is that intended to add the labels in line?

return
for resource in ctx.resource_list["items"]:
if resource["kind"] == "Ingress" and resource["spec"]["rules"][0]["host"] == placeHolderHostname:
fail(errMsg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, this should be appended to ResourceList.Results but it's not quite supported yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

@yuwenma
Copy link
Contributor

yuwenma commented Jul 21, 2022

I like this approach!

Copy link
Contributor

@yuwenma yuwenma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! A minor comment about removing the in-line labels

@droot
Copy link
Contributor Author

droot commented Jul 22, 2022

Is that intended to add the labels in line?

Can you elaborate more on this. The labels are added by set-labels function and I think previously published package didn't have the result of kpt fn render.


for env in container["env"]:
if env["name"] == "GHOST_HOST":
env["value"] = host
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOC, is ApplyReplacements capable of copying the host value from the Ingress resource to this environment variable in the associative list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check.

Let's say if ApplyReplacements supports that, then, are you thinking of treating the value of host in ingress resource to be source of truth ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the docs says it is possible to target value in a sequence node, so will give it a try.

https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/replacements/#field-path-format

errMsg = "Blog's hostname must be specified in fn/update-blog-host.yaml"
placeHolderHostname = "example.com"
for resource in resources:
# this is an abstract package, so ignore host name validation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should have a first-class way to query this in our sdks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, validation functions needs this bit, so a helper in SDK will help.

/cc @yuwenma

@droot
Copy link
Contributor Author

droot commented Jul 24, 2022

Using ApplyReplacements instead of Starlark for propagating the values. Also improved the validation function. So good enough for merging. Also I will be moving the package-examples to kpt-samples repo after tagging this version.

@droot droot merged commit b1498b5 into kptdev:main Jul 24, 2022
chunglu-chou pushed a commit to chunglu-chou/kpt that referenced this pull request Aug 20, 2022
* using apply-replacements to propagate the values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants